package com.sgb.jicai.view.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.ScreenUtils;
import com.sgb.jicai.R;
import com.sgb.jicai.databinding.ActivityJcSupplierpublishBinding;
import com.sgb.jicai.entity.DetailsBean;
import com.sgb.jicai.entity.PriceRulesBean;
import com.sgb.jicai.entity.SupplierPublishBean;
import com.sgb.jicai.viewmodel.SupplierPublishModel;
import com.sgb.link.entity.BrandEntity;
import com.swgk.core.base.AppActivity;
import com.swgk.core.customview.PhotoViewActivity;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.entity.GoodsPublishEntity;
import com.swgk.core.view.entity.MenuEntity;
import com.sgb.jicai.entity.BaseAddFiledBean;
import com.sgb.jicai.entity.CommodityUseAddFiledBean;
import com.sgb.jicai.entity.JiCaiCustomFieldBean;
import com.sgb.jicai.entity.JiCaiPublishListBean;
import com.sgb.jicai.entity.SuperviseListBean;
import com.sgb.jicai.view.adapter.SuperviseAdapter;
import com.sgb.link.view.adapter.SelfTeamPicAdapter;
import com.sgb.link.utils.NumericalTransformationTool;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.swgk.core.view.pop.GoodsTypePopWindow;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.CommonDialog;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import java.io.File;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Time:2021/7/19
 * AUTHOR:F_Q
 * Description: 供方发起发布
 */
public class JiCaiSupplierPublishAct extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    SupplierPublishModel viewModel;
    private ActivityJcSupplierpublishBinding binding;
    //发布请求bean
    private SupplierPublishBean bean;
    //商品主图的adapter
    private SelfTeamPicAdapter mPicAdapter;
    //按类型设置监督人的adapter
    String[] superviseListTitle = new String[]{"行贿受贿", "服务态度", "商业欺诈", "违约纠纷", "工作作风", "工作纠偏", "其他监督人"};
    List<SuperviseListBean> superviseList = new ArrayList<>();
    private SuperviseAdapter superviseadapter;
    //公司名称
    private String company_name;
    //公司no
    private String company_no;
    //省市区三级联动
    // 一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 二级联动数据
    private List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    // 三级联动数据
    private int cityPosition1;
    private int cityPosition2;
    //发起单位列表
    private List<JiCaiPublishListBean> companyList;
    //用户信息列表
    private List<JiCaiPublishListBean> UserList;
    //发起部门
    private List<JiCaiPublishListBean> departmentList;
    //付款类型
    private List<JiCaiPublishListBean> paymentList;
    //发票类型
    private List<JiCaiPublishListBean> invoiceList;
    //税率列表
    private List<JiCaiPublishListBean> taxRateList;
    //集采单位列表
    private List<JiCaiPublishListBean> unitList;
    //品牌列表
    private List<JiCaiPublishListBean> brandList;
    //商品列表
    private List<MenuEntity<MenuEntity<MenuEntity>>> goodsTypeEntityList;
    //商品主图list
    private List<String> files;
    /***
     * 商品分类弹窗
     */
    private GoodsTypePopWindow goodsTypePopWindow;
    private int REQUESTCODE = 500;
    private String userName = "";
    private String companyId = "";
    private boolean isProductModel = false;//是否存在规格型号

    @Override
    protected void initView() {
        super.initView();
        bean = new SupplierPublishBean();
        binding = DataBindingUtil.setContentView(this, R.layout.activity_jc_supplierpublish);
        viewModel = new ViewModelProvider(this).get(SupplierPublishModel.class);
        viewModel.setActivity(JiCaiSupplierPublishAct.this);
        binding.topLayout.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (binding.supplierBasics.getRoot().getVisibility() == View.VISIBLE) {
                    onBackPressed();
                } else {
                    binding.supplierBasics.getRoot().setVisibility(View.VISIBLE);
                    binding.supplierPrivilege.getRoot().setVisibility(View.GONE);
                    binding.supplierContentProgress.setProgressbar(50);
                }
            }
        });
        binding.topLayout.titleView.setText("供方发起");
        ViewOnClick();//初始化点击事件
        basicsView();//基础信息模块view初始化
        imtvView();//图文描述模块view初始化
        initPopWindow();//初始化商品弹窗信息
    }

    @Override
    protected void init() {
        super.init();
        //基础信息
        company_name = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NAME, "");
        company_no = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO, "");
        userName = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_NAME, "");
        viewModel.getCompanyList(new View(this), false);//调用接口获取主企业id
        viewModel.getUserList(new View(this), false);
        //发起公司
        binding.supplierBasics.basic.publishUnits.setContent(company_name);//回显主企业名称
        //联系人
        binding.supplierBasics.basic.contactName.setContent(userName + "");
        //联系电话
        binding.supplierBasics.basic.contact.setContent(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, "") + "");
        binding.supplierBasics.basic.contact.setInfilterType(ItemInputTextView.TYPE_PHONE);
        //集采信息
        binding.supplierBasics.jicai.initialEnergy.setInfilterType(ItemInputTextView.TYPE_NUM);
        //图文信息
        //物流信息
        //其他信息
        //初始化字段、默认设置值  publish_units
        bean.setSuperviseType("1");//监督人设置类型 1 统一设置监督人 2按类型设置监督人
        bean.setCompanyNo(company_no);//创建公司编号
        bean.setCompanyName(company_name);//创建公司名称
        bean.setPickCompanyName(company_name);//选择的公司名称
        bean.setJoinTraderType("2");//加盟方身份要求 1公司及个人 2公司
        bean.setIsDelivery("1");//是否送货：1是，0自提
        bean.setDeliveryType("1");//配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
        bean.setLoadType("1");//是否免费装车1是，0否
        bean.setUploadType("0");//是否免费卸车1是，0否
        bean.setFreeInstall("1");//是否免费安装1是，0否
        //交流信息接收人
        binding.supplierBasics.basic.communicationReceiveName.setContent(userName + "");
        bean.setCommunicationUserName(userName + "");
        //函询接收人
        binding.supplierBasics.basic.letterReceiveName.setContent(userName + "");
        bean.setInquiryUserName(userName + "");
        //监督接收人
        binding.supplierBasics.basic.superviseReceiveName.setContent(userName + "");

    }

    private void ViewOnClick() {
        //主按钮
        binding.supplierBasics.nextStep.setOnClickListener(this);//下一步
        binding.supplierPrivilege.previousStep.setOnClickListener(this);//上一步
        binding.supplierPrivilege.submit.setOnClickListener(this);//提交
        //基础信息
        binding.supplierBasics.basic.llSuperviseCheckbox1.setOnClickListener(this);//统一设置监督人按钮
        binding.supplierBasics.basic.llSuperviseCheckbox2.setOnClickListener(this);//按类型设置监督人
        //ItemInputTextView点击事件
        binding.supplierBasics.basic.publishUnits.setOnWholeItemClickListener(this);//发起单位
        binding.supplierBasics.basic.startDepartment.setOnWholeItemClickListener(this);//发起部门
        binding.supplierBasics.basic.jicaiScope.setOnWholeItemClickListener(this);//集采范围
        binding.supplierBasics.basic.communicationReceiveName.setOnWholeItemClickListener(this);//交流信息接收人
        binding.supplierBasics.basic.warehouseLand.setOnWholeItemClickListener(this);//仓储地
        binding.supplierBasics.basic.buyTime.setOnWholeItemClickListener(this);//集采截止时间
        binding.supplierBasics.basic.letterReceiveName.setOnWholeItemClickListener(this);//函询接收人
        binding.supplierBasics.basic.superviseReceiveName.setOnWholeItemClickListener(this);//监督接收人
        //集采信息
        //ItemInputTextView点击事件
        binding.supplierBasics.jicai.goodsType.setOnWholeItemClickListener(this);//商品类型
        binding.supplierBasics.jicai.productModel.setOnWholeItemClickListener(this);//规格型号
        binding.supplierBasics.jicai.unitMeasure.setOnWholeItemClickListener(this);//计量单位
        binding.supplierBasics.jicai.rangeBrands.setOnWholeItemClickListener(this);//品牌范围
        //图文描述
        //配送方式
        binding.supplierPrivilege.dispatching.llMerchantShipping.setOnClickListener(this);//商家配送
        binding.supplierPrivilege.dispatching.llAllGratis.setOnClickListener(this);//免费配送
        binding.supplierPrivilege.dispatching.llPartGratis.setOnClickListener(this);//部分免费,超标收费
        binding.supplierPrivilege.dispatching.llChargeDistribution.setOnClickListener(this);//收费配送
        binding.supplierPrivilege.dispatching.llToMention.setOnClickListener(this);//需方自提
        //其他
        binding.supplierPrivilege.surplus.cbGratisGoods.setOnClickListener(this);//免费配送
        binding.supplierPrivilege.surplus.cbGratisUnload.setOnClickListener(this);//免费卸车
        binding.supplierPrivilege.surplus.llCbGratisInstall.setOnClickListener(this);//免费安装
        binding.supplierPrivilege.surplus.llCbPayInstall.setOnClickListener(this);//收费安装
        //ItemInputTextView点击事件
        binding.supplierPrivilege.surplus.paymentType.setOnWholeItemClickListener(this);//付款方式
        binding.supplierPrivilege.surplus.invoiceType.setOnWholeItemClickListener(this);//发票类型
        binding.supplierPrivilege.surplus.taxRate.setOnWholeItemClickListener(this);//税率

        //集采采购起始量
        binding.supplierBasics.jicai.initialEnergy.onTextChange(new ItemInputTextView.onTextChange() {
            @Override
            public void change(String s) {
                int length = s.length();
                if (length == 1 && s.equals("0")) {
                    binding.supplierBasics.jicai.initialEnergy.setContent("");
                }
            }
        });
        //gratis_kilometre  免费配送距离
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.dispatching.gratisKilometre);
        //kilometre  超出收费标准  公里
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.dispatching.kilometre);
        //cost  超出收费标准  费用
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.dispatching.cost);
        //charge_kilometre  收费配送  公里
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.dispatching.chargeKilometre);
        //charge_cost  收费配送  费用
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.dispatching.chargeCost);
        //installation_charge  安装费用
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.surplus.installationCharge);
        //质保时间
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.surplus.guaranteeTime);
        //免费维修数量
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.surplus.gratisRepairTime);
        //付款比例
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.surplus.paymentRatio);
        //尾款支付周期
        NumericalTransformationTool.setMonitor(binding.supplierPrivilege.surplus.paymentPeriod);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.next_step) {//下一步
            //点击下一步时进行数据效验
            NextStepData(bean);
        } else if (id == R.id.previous_step) {//上一步
            binding.supplierBasics.getRoot().setVisibility(View.VISIBLE);
            binding.supplierPrivilege.getRoot().setVisibility(View.GONE);
            binding.supplierContentProgress.setProgressbar(50);
            binding.scrollview.scrollTo(0,0);
        } else if (id == R.id.submit) {//提交信息
            submitData(bean);
        } else if (id == R.id.ll_supervise_checkbox1) {//统一设置监督人按钮
            bean.setSuperviseType("1");
            binding.supplierBasics.basic.superviseCheckbox1.setChecked(true);
            binding.supplierBasics.basic.superviseCheckbox2.setChecked(false);
            //按类型设置监督人的列表布局隐藏
            binding.supplierBasics.basic.superviseList.setVisibility(View.GONE);
            //统一监督人
            binding.supplierBasics.basic.superviseReceiveName.setVisibility(View.VISIBLE);
        } else if (id == R.id.ll_supervise_checkbox2) {//按类型设置监督人
            bean.setSuperviseType("2");
            binding.supplierBasics.basic.superviseCheckbox1.setChecked(false);
            binding.supplierBasics.basic.superviseCheckbox2.setChecked(true);
            //按类型设置监督人的列表布局展示
            binding.supplierBasics.basic.superviseList.setVisibility(View.VISIBLE);
            //统一监督人
            binding.supplierBasics.basic.superviseReceiveName.setVisibility(View.GONE);
        } else if (id == R.id.ll_merchant_shipping) {//商家配送
            bean.setIsDelivery("1");//是否送货：1是，0自提
            bean.setDeliveryType("1");//配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
            binding.supplierPrivilege.dispatching.merchantDistribution.setVisibility(View.VISIBLE);
            binding.supplierPrivilege.dispatching.cbAllGratis.setChecked(true);
            binding.supplierPrivilege.dispatching.ivMerchantShipping.setChecked(true);
            binding.supplierPrivilege.dispatching.ivToMention.setChecked(false);
            binding.supplierPrivilege.dispatching.cbPartGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.cbChargeDistribution.setChecked(false);
        } else if (id == R.id.ll_all_gratis) {//免费配送
            bean.setDeliveryType("1");//配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
            binding.supplierPrivilege.dispatching.cbAllGratis.setChecked(true);
            binding.supplierPrivilege.dispatching.cbPartGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.cbChargeDistribution.setChecked(false);
        } else if (id == R.id.ll_part_gratis) {//部分免费,超标收费
            bean.setDeliveryType("2");//配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
            binding.supplierPrivilege.dispatching.cbAllGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.cbPartGratis.setChecked(true);
            binding.supplierPrivilege.dispatching.cbChargeDistribution.setChecked(false);
        } else if (id == R.id.ll_charge_distribution) {//收费配送
            bean.setDeliveryType("3");//配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
            binding.supplierPrivilege.dispatching.cbAllGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.cbPartGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.cbChargeDistribution.setChecked(true);
        } else if (id == R.id.ll_to_mention) {//需方自提
            bean.setIsDelivery("0");//是否送货：1是，0自提
            bean.setDeliveryType("");//配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
            binding.supplierPrivilege.dispatching.merchantDistribution.setVisibility(View.GONE);
            binding.supplierPrivilege.dispatching.cbAllGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.ivToMention.setChecked(true);
            binding.supplierPrivilege.dispatching.ivMerchantShipping.setChecked(false);
            binding.supplierPrivilege.dispatching.cbPartGratis.setChecked(false);
            binding.supplierPrivilege.dispatching.cbChargeDistribution.setChecked(false);
        } else if (id == R.id.cb_gratis_goods) {//免费配送//是否免费装车1是，0否
            if (binding.supplierPrivilege.surplus.cbGratisGoods.isChecked()) {
                bean.setLoadType("1");
                binding.supplierPrivilege.surplus.cbGratisGoods.setChecked(true);
            } else {
                bean.setLoadType("0");
                binding.supplierPrivilege.surplus.cbGratisGoods.setChecked(false);
            }
        } else if (id == R.id.cb_gratis_unload) {//免费卸车//是否免费卸车1是，0否
            if (binding.supplierPrivilege.surplus.cbGratisUnload.isChecked()) {
                bean.setUploadType("1");
                binding.supplierPrivilege.surplus.cbGratisUnload.setChecked(true);
            } else {
                bean.setUploadType("0");
                binding.supplierPrivilege.surplus.cbGratisUnload.setChecked(false);
            }
        } else if (id == R.id.ll_cb_gratis_install) {//免费安装
            bean.setFreeInstall("1");//是否免费安装1是，0否
            binding.supplierPrivilege.surplus.cbGratisInstall.setChecked(true);
            binding.supplierPrivilege.surplus.cbPayInstall.setChecked(false);
            binding.supplierPrivilege.surplus.llInstallationCharge.setVisibility(View.GONE);
        } else if (id == R.id.ll_cb_pay_install) {//收费安装
            bean.setFreeInstall("0");//是否免费安装1是，0否
            binding.supplierPrivilege.surplus.cbGratisInstall.setChecked(false);
            binding.supplierPrivilege.surplus.cbPayInstall.setChecked(true);
            binding.supplierPrivilege.surplus.llInstallationCharge.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        int id = view.getId();//集采范围
//交流信息接收人
        if (id == R.id.publish_units) {//发起单位
            if (companyList == null) {
                viewModel.getCompanyList(view, true);
            } else {
                showListPop("发起单位", view, companyList);
            }
        } else if (id == R.id.start_department) {//发起部门
            viewModel.getDepartmentList(bean.getPickCompanyId(), view);
        } else if (id == R.id.jicai_scope || id == R.id.warehouse_land) {//仓储地
            if (addressEntityList == null) {
                viewModel.getAddressList(view);
            } else {
                showCityPop("选择城市", view);
            }
        } else if (id == R.id.communication_receive_name || id == R.id.letter_receive_name) {//函询接收人
            if (UserList == null) {
                viewModel.getUserList(view, true);
            }
            showListPop("选择接收人", view, UserList);
        } else if (id == R.id.supervise_receive_name) {//监督接收人
            if (UserList == null) {
                viewModel.getUserList(view, true);
            }
            showListPop("选择监督人", view, UserList);
        } else if (id == R.id.buy_time) {//集采截止时间
            showTimePop();
        } else if (id == R.id.goods_type) {//商品类型
            if (goodsTypeEntityList != null) {
                showGoodsTypePop();
            } else {
                viewModel.getGoodsCategory();
            }
        } else if (id == R.id.product_model) {//规格型号
            if (TextUtils.isEmpty(bean.getThirdType())) {
                MToast.showToast(this, "请选择商品类型");
                return;
            }
            if (TextUtils.isEmpty(binding.supplierBasics.jicai.initialEnergy.getContent())) {
                MToast.showToast(this, "请输入采购起始量");
                return;
            } else {
                bean.setLowBuy(binding.supplierBasics.jicai.initialEnergy.getContent());
            }
            if (TextUtils.isEmpty(binding.supplierBasics.jicai.unitMeasure.getContent())) {
                MToast.showToast(this, "请选择计量单位");
                return;
            }
            if (TextUtils.isEmpty(binding.supplierBasics.jicai.rangeBrands.getContent())) {
                MToast.showToast(this, "请选择品牌范围");
                return;
            }
            if (TextUtils.isEmpty(binding.supplierBasics.jicai.productModel.getContent())) {
                isProductModel = false;
            } else {
                isProductModel = true;
            }
            Intent intent = new Intent(this, JiCaiProductModelAct.class);
            intent.putExtra("bean", bean);
            intent.putExtra("isProductModel", isProductModel);
            startActivityForResult(intent, REQUESTCODE);
        } else if (id == R.id.unit_measure) {//计量单位
            if (unitList == null) {
                viewModel.getUnitList(view);
            } else {
                showListPop("选择计量单位", view, unitList);
            }
        } else if (id == R.id.range_brands) {//品牌范围
            if (TextUtils.isEmpty(bean.getThirdType())) {
                MToast.showToast(this, "请选择商品类型");
                return;
            }
            viewModel.getRangeBrandsList(bean.getThirdType(), view);
        } else if (id == R.id.payment_type) {//付款方式
            if (paymentList == null) {
                viewModel.getPaymentType(view);
            } else {
                showListPop("选择付款方式", view, paymentList);
            }
        } else if (id == R.id.invoice_type) {//发票类型
            if (invoiceList == null) {
                viewModel.getInvoiceType(view);
            } else {
                showListPop("选择发票类型", view, invoiceList);
            }
        } else if (id == R.id.tax_rate) {//税率
            if (taxRateList == null) {
                viewModel.getTaxRate(view);
            } else {
                showListPop("选择税率", view, taxRateList);
            }
        }
    }

    /**
     * 下一步供方发起数据信息
     *
     * @param oneBean
     */
    private void NextStepData(SupplierPublishBean oneBean) {
        if (TextUtils.isEmpty(binding.supplierBasics.basic.publishUnits.getContent())) {
            MToast.showToast(this, "请选择发起单位");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.contactName.getContent())) {
            MToast.showToast(this, "请输入联系人");
            return;
        } else {
            oneBean.setContacts(binding.supplierBasics.basic.contactName.getContent());
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.contact.getContent())) {
            MToast.showToast(this, "请输入联系方式");
            return;
        } else if (!CheckUtils.isPhoneNumberValid(binding.supplierBasics.basic.contact.getContent())) {
            MToast.showToast(this, "请输入正确格式的联系方式");
            return;
        } else {
            oneBean.setContactNumber(binding.supplierBasics.basic.contact.getContent());
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.jicaiScope.getContent())) {
            MToast.showToast(this, "请选择集采范围");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.communicationReceiveName.getContent())) {
            MToast.showToast(this, "请选择交流信息接收人");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.warehouseLand.getContent())) {
            MToast.showToast(this, "请选择仓储地");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.detailedAddress.getEditContent())) {
            MToast.showToast(this, "请填写详细收货地址");
            return;
        } else {
            oneBean.setStorageDetailsAddress(binding.supplierBasics.basic.detailedAddress.getEditContent());
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.buyTime.getContent())) {
            MToast.showToast(this, "请选择集采截止时间");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.basic.letterReceiveName.getContent())) {
            MToast.showToast(this, "请选择函询接收人");
            return;
        }
        if (oneBean.getSuperviseType().equals("1")) {
            if (TextUtils.isEmpty(binding.supplierBasics.basic.superviseReceiveName.getContent())) {
                MToast.showToast(this, "请选择监督接收人员");
                return;
            }
        }
        if (oneBean.getSuperviseType().equals("2")) {
            if (superviseadapter!=null&&superviseadapter.getDatas().size()>0){
                bean.setSuperviseList(superviseadapter.getDatas());
                for (SuperviseListBean superviseListBean : bean.getSuperviseList()) {
                    if (TextUtils.isEmpty(superviseListBean.getSuperviseUserName())) {
                        MToast.showToast(this, "请选择" + superviseListBean.getName() + "监督人");
                        return;
                    }
                }
            }
        }
        if (TextUtils.isEmpty(binding.supplierBasics.jicai.goodsType.getContent())) {
            MToast.showToast(this, "请选择商品类型");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.jicai.initialEnergy.getContent())) {
            MToast.showToast(this, "请输入采购起始量");
            return;
        } else {
            oneBean.setLowBuy(binding.supplierBasics.jicai.initialEnergy.getContent());
        }
        if (TextUtils.isEmpty(binding.supplierBasics.jicai.unitMeasure.getContent())) {
            MToast.showToast(this, "请选择计量单位");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.jicai.rangeBrands.getContent())) {
            MToast.showToast(this, "请选择品牌范围");
            return;
        }
        if (TextUtils.isEmpty(binding.supplierBasics.jicai.productModel.getContent())) {
            MToast.showToast(this, "请选择规格型号");
            return;
        }
        //基础自定义字段
        List<JiCaiCustomFieldBean> basicCustomFieldData = binding.supplierBasics.basic.basicCustomField.getCustomFieldViewData();
        List<BaseAddFiledBean> BaseAddFiledBeanlist = new ArrayList<>();
        if (basicCustomFieldData != null && basicCustomFieldData.size() > 0) {
            for (JiCaiCustomFieldBean basiccustomfielddata : basicCustomFieldData) {
                if (TextUtils.isEmpty(basiccustomfielddata.getKey())) {
                    MToast.showToast(this, "请完善基础信息自定义字段");
                    return;
                }
                if (TextUtils.isEmpty(basiccustomfielddata.getVal())) {
                    MToast.showToast(this, "请完善基础信息自定义字段");
                    return;
                }
                BaseAddFiledBeanlist.add(new BaseAddFiledBean(basiccustomfielddata.getKey() + "", basiccustomfielddata.getVal() + ""));
            }
        }
        oneBean.setBaseAddFiled(BaseAddFiledBeanlist);//基础自定义字段
        //图文自定义字段
        List<JiCaiCustomFieldBean> customFieldViewData = binding.supplierBasics.imtv.imtvCustomField.getCustomFieldViewData();
        List<CommodityUseAddFiledBean> commodityuseaddfiledlist = new ArrayList<>();
        if (customFieldViewData != null && customFieldViewData.size() > 0) {
            for (JiCaiCustomFieldBean customFieldViewDatum : customFieldViewData) {
                if (TextUtils.isEmpty(customFieldViewDatum.getKey())) {
                    MToast.showToast(this, "请完善图文描述中自定义字段");
                    return;
                }
                if (TextUtils.isEmpty(customFieldViewDatum.getVal())) {
                    MToast.showToast(this, "请完善图文描述中自定义字段");
                    return;
                }
                commodityuseaddfiledlist.add(new CommodityUseAddFiledBean(customFieldViewDatum.getKey() + "", customFieldViewDatum.getVal() + ""));
            }
        }
        oneBean.setCommodityUseAddFiled(commodityuseaddfiledlist);//  图文自定义字段
        oneBean.setCommodityTechnology(binding.supplierBasics.imtv.goodsProcess.getEditText() + "");//商品工艺
        oneBean.setCommodityUse(binding.supplierBasics.imtv.useGoods.getEditText() + "");//商品用途
        oneBean.setQualityDescription(binding.supplierBasics.imtv.qualityStandard.getEditText() + "");//质量标准
        oneBean.setRichText(binding.supplierBasics.imtv.productDetails.getEditText() + "");//商品详情
        for (String data : mPicAdapter.getDatas()) {
            if (!TextUtils.equals(data, "add")) {
                if (!data.contains("https://")) {//没有上传过的图
                    File file = new File(data);
                    viewModel.uploadAvatarFileModel(file, 5, oneBean);
                } else {//上传过的图
                    if (files == null) {
                        files = new ArrayList<>();
                    }
                    files.add(data);
                }
            }
        }

       if (mPicAdapter.getDatas().size()<=1){
           MToast.showToast(this, "请选择商品主图");
           return;

       }
        //集采优惠的单位设置
        binding.supplierPrivilege.dispatching.gratisUnit.setText("元/" + bean.getUnitName());//超出收费标准的单位
        binding.supplierPrivilege.dispatching.chargeUnit.setText("元/" + bean.getUnitName());//收费配送的单位
        binding.supplierPrivilege.surplus.installUnit.setText("元/" + bean.getUnitName());//收费安装的单位
        binding.supplierBasics.getRoot().setVisibility(View.GONE);
        binding.supplierPrivilege.getRoot().setVisibility(View.VISIBLE);
        binding.supplierContentProgress.setProgressbar(100);
        binding.scrollview.scrollTo(0, 0);
    }

    /**
     * 提交数据信息，效验数据
     *
     * @param subBean
     */
    private void submitData(SupplierPublishBean subBean) {
        //是否送货：1是，0自提
        if (subBean.getIsDelivery().equals("1")) {
            //配送方式 (1 免费配送  2部分免费，超标付费  3收费配送)
            switch (subBean.getDeliveryType()) {
                case "1"://免费配送
                    break;
                case "2"://部分免费，超标付费gratis_kilometre
                    if (TextUtils.isEmpty(binding.supplierPrivilege.dispatching.gratisKilometre.getText().toString().trim())) {
                        MToast.showToast(this, "请输入免费配送距离");
                        return;
                    } else {
                        subBean.setFreeKil(binding.supplierPrivilege.dispatching.gratisKilometre.getText().toString().trim());
                    }
                    if (TextUtils.isEmpty(binding.supplierPrivilege.dispatching.kilometre.getText().toString().trim())) {
                        MToast.showToast(this, "请输入超出收费标准的公里数");
                        return;
                    } else {
                        subBean.setDeliverySection(binding.supplierPrivilege.dispatching.kilometre.getText().toString().trim());
                    }
                    if (TextUtils.isEmpty(binding.supplierPrivilege.dispatching.cost.getText().toString().trim())) {
                        MToast.showToast(this, "请填写超出收费标准的费用");
                        return;
                    } else {
                        subBean.setDeliverySectionCost(binding.supplierPrivilege.dispatching.cost.getText().toString().trim());
                    }
                    break;
                case "3"://收费配送charge_kilometre  charge_cost
                    if (TextUtils.isEmpty(binding.supplierPrivilege.dispatching.chargeKilometre.getText().toString().trim())) {
                        MToast.showToast(this, "请输入写收费配送的公里数");
                        return;
                    } else {
                        subBean.setDeliverySection(binding.supplierPrivilege.dispatching.chargeKilometre.getText().toString().trim());
                    }
                    if (TextUtils.isEmpty(binding.supplierPrivilege.dispatching.chargeCost.getText().toString().trim())) {
                        MToast.showToast(this, "请填写写收费配送的费用");
                        return;
                    } else {
                        subBean.setDeliverySectionCost(binding.supplierPrivilege.dispatching.chargeCost.getText().toString().trim());
                    }
                    break;

            }
        }
        //是否免费安装1是，0否
        if (subBean.getFreeInstall().equals("0")) {
            if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.installationCharge.getText().toString().trim())) {
                MToast.showToast(this, "请填写安装费用");
                return;
            } else {
                subBean.setInstallCost(binding.supplierPrivilege.surplus.installationCharge.getText().toString().trim());
            }
        }
        if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.guaranteeTime.getText().toString().trim())) {
            MToast.showToast(this, "请填写质保时间");
            return;
        } else {
            subBean.setQualityCycle(binding.supplierPrivilege.surplus.guaranteeTime.getText().toString().trim());
        }
        //免费维修月数量
        subBean.setRepairCycle(binding.supplierPrivilege.surplus.gratisRepairTime.getText().toString().trim());
        if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.paymentType.getContent())) {
            MToast.showToast(this, "请选择付款方式");
            return;
        }
        //付款方式 (1 预付款  2货到付款  3其他)
        if (subBean.getPayType().equals("1")) {
            if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.paymentRatio.getText().toString().trim())) {
                MToast.showToast(this, "请填写付款比例");
                return;
            } else {
                subBean.setPayRatio(binding.supplierPrivilege.surplus.paymentRatio.getText().toString().trim());
            }
            if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.paymentPeriod.getText().toString().trim())) {
                MToast.showToast(this, "请填写尾款支付周期");
                return;
            } else {
                subBean.setFinalPaymentDay(binding.supplierPrivilege.surplus.paymentPeriod.getText().toString().trim());
            }
        }
        if (subBean.getPayType().equals("3")) {
            if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.elsePaymentType.getContent())) {
                MToast.showToast(this, "请填写其他付款方式");
                return;
            } else {
                subBean.setOtherPayType(binding.supplierPrivilege.surplus.elsePaymentType.getContent());
            }
        }
        if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.invoiceType.getContent())) {
            MToast.showToast(this, "请选择发票类型");
            return;
        }
        //发票类型：1 不带票 2增值税专用票
        if (subBean.getBillType().equals("2")) {
            if (TextUtils.isEmpty(binding.supplierPrivilege.surplus.taxRate.getContent())) {
                MToast.showToast(this, "请选择税率");
                return;
            }
        }
        //集采优惠的自定义字段
        List<JiCaiCustomFieldBean> basicCustomFieldData = binding.supplierPrivilege.surplus.privilegeCustomField.getCustomFieldViewData();
        Map<String, String> map = new HashMap<>();
        if (basicCustomFieldData != null && basicCustomFieldData.size() > 0) {
            for (JiCaiCustomFieldBean basiccustomfielddata : basicCustomFieldData) {
                if (TextUtils.isEmpty(basiccustomfielddata.getKey())) {
                    MToast.showToast(this, "请完善集采优惠中自定义字段");
                    return;
                }
                if (TextUtils.isEmpty(basiccustomfielddata.getVal())) {
                    MToast.showToast(this, "请完善集采优惠中自定义字段");
                    return;
                }
                map.put(basiccustomfielddata.getKey() + "", basiccustomfielddata.getVal() + "");
            }
        }
        subBean.setAddJson(map);//集采优惠的自定义字段
        if (files!=null&&files.size()>0&&files.size() == mPicAdapter.getRealCount()) {
            List<String> filesArry = new ArrayList<>();
            for (String file : files) {
                String replace = file.replace("https://shigongbang.oss-cn-hangzhou.aliyuncs.com/", "");
                filesArry.add(replace);
            }
            //bean类赋值
            subBean.setMainImage(new Gson().toJson(filesArry));
        }
        viewModel.SupplierPublish(subBean);
    }

    /**
     * 数据回显
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                mPicAdapter.setPicData(selectList);
            }
            if (requestCode == REQUESTCODE) {
                String type = data.getStringExtra("type");
                if (type.equals("1")) {
                    List<DetailsBean> adapterDatas = (List<DetailsBean>) data.getSerializableExtra("adapter");
                    if (adapterDatas != null && adapterDatas.size() > 0) {
                        bean.setDetails(adapterDatas);
                        binding.supplierBasics.jicai.productModel.setContent("已完成");
                    }
                } else {
                    String price = data.getStringExtra("price");
                    List<DetailsBean> adapterDatas = new ArrayList<>();
                    List<PriceRulesBean> PriceRulesList = (List<PriceRulesBean>) data.getSerializableExtra("data");
                    if (PriceRulesList != null && PriceRulesList.size() > 0) {
                        DetailsBean detailsBean = new DetailsBean(bean.getBrandsName(), bean.getBrandsNo(), bean.getLowBuy(), bean.getUnit(), new ArrayList<>(), "", bean.getUnitName());
                        //每个商品条目默认带一个价格区间列表
                        detailsBean.setPriceRules(PriceRulesList);
                        detailsBean.setOriginalPrice(price + "");
                        adapterDatas.add(detailsBean);
                        bean.setDetails(adapterDatas);
                        binding.supplierBasics.jicai.productModel.setContent("已完成");
                    }
                }
            }
        }
    }

    /**
     * 基础信息模块view初始化
     */
    private void basicsView() {
        for (int i = 0; i < superviseListTitle.length; i++) {
            //监督信息接收人信息
            SuperviseListBean bean = new SuperviseListBean();
            bean.setAccusationItem(i + 1 + "");
            bean.setName(superviseListTitle[i]);
            superviseList.add(bean);
        }
        superviseadapter = new SuperviseAdapter(this, superviseList);
        binding.supplierBasics.basic.superviseList.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.supplierBasics.basic.superviseList.setAdapter(superviseadapter);
        superviseadapter.setOnItemClick(new AdapterOnItemClick<SuperviseListBean>() {
            @Override
            public void onItemClick(SuperviseListBean bean, int position) {
                //选择框调用
                if (UserList == null) {
                    viewModel.getUserList(new View(getApplicationContext()),false);
                }
                if (UserList != null && UserList.size() > 0) {
                    showSuperviseListPop("选择接收人", bean, UserList);
                }
            }
        });

    }

    /**
     * 图文描述模块view初始化
     */
    private void imtvView() {
        GridLayoutManager manager = new GridLayoutManager(this, 4);
        binding.supplierBasics.imtv.recyclerView.setLayoutManager(manager);
        mPicAdapter = new SelfTeamPicAdapter(this, new ArrayList<>(), 8, manager);
        binding.supplierBasics.imtv.recyclerView.setHasFixedSize(false);
        binding.supplierBasics.imtv.recyclerView.addItemDecoration(new GridSpacingItemDecoration(4, ScreenUtils.dip2px(this, 5), true));
        binding.supplierBasics.imtv.recyclerView.setAdapter(mPicAdapter);
        mPicAdapter.setOnItemClick(new AdapterOnItemClick<String>() {
            @Override
            public void onItemClick(String s, int position) {
                if (TextUtils.isEmpty(s)) {
                    viewModel.pictureSelector(mPicAdapter.hasCount(), PictureConfig.CHOOSE_REQUEST);
                } else {
                    List<String> newImg = new ArrayList<>();
                    if (mPicAdapter.getDatas() != null && mPicAdapter.getDatas().size() != 0) {
                        if ("add".equals(mPicAdapter.getDatas().get(mPicAdapter.getDatas().size() - 1))) {
                            for (int i = 0; i < mPicAdapter.getDatas().size(); i++) {
                                if (i != mPicAdapter.getDatas().size() - 1) {
                                    newImg.add(mPicAdapter.getDatas().get(i));
                                }
                            }
                        }
                    }
                    Intent intent = new Intent(getActivity(), PhotoViewActivity.class);
                    intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) newImg);
                    intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
                    startActivity(intent);
                }
            }
        });
    }

    private void initPopWindow() {
        if (goodsTypePopWindow == null) {
            goodsTypePopWindow = new GoodsTypePopWindow(this);
        }
        goodsTypePopWindow.setBgView(binding.grayLayout);
        goodsTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                GoodsPublishEntity goodsPublishEntity = (GoodsPublishEntity) key1;
                //一级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid1Name()) && !TextUtils.isEmpty(goodsPublishEntity.getCid1())) {
                    bean.setFirstTypeName(goodsPublishEntity.getCid1Name());
                    bean.setFirstType(goodsPublishEntity.getCid1());
                }
                //二级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid2Name()) && !TextUtils.isEmpty(goodsPublishEntity.getCid2())) {
                    bean.setSecondTypeName(goodsPublishEntity.getCid2Name());
                    bean.setSecondType(goodsPublishEntity.getCid2());
                }
                //三级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid3Name()) && !TextUtils.isEmpty(goodsPublishEntity.getCid3())) {
                    bean.setThirdTypeName(goodsPublishEntity.getCid3Name());
                    bean.setThirdType(goodsPublishEntity.getCid3());
                }
                binding.supplierBasics.jicai.goodsType.setContent(goodsPublishEntity.getCid1Name() + "/" + goodsPublishEntity.getCid2Name() + "/" + goodsPublishEntity.getCid3Name());
                binding.supplierBasics.jicai.initialEnergy.setContent("");//采购量置空
                binding.supplierBasics.jicai.unitMeasure.setContent("");//单位
                bean.setUnitName("");
                bean.setUnit("");
                binding.supplierBasics.jicai.rangeBrands.setContent("");//品牌
                bean.setBrandsName("");
                bean.setBrandsNo("");
                binding.supplierBasics.jicai.productModel.setContent("");//规格型号
                //清空规格型号字段
                List<DetailsBean> adapterDatas = new ArrayList<>();
                bean.setDetails(adapterDatas);
            }
        });
    }

    /**
     * 省市的选择
     *
     * @param titles
     * @param views
     */
    private void showCityPop(String titles, View views) {
        CityPickView cityOption = new CityPickBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                int id = views.getId();
                if (id == R.id.jicai_scope) {
                    binding.supplierBasics.basic.jicaiScope.setContent(addressEntityList.get(options1).getName() + " / " + opt2.get(options1).get(options2).getName());
                    bean.setProvinceName(addressEntityList.get(options1).getName() + "");
                    bean.setProvinceNo(addressEntityList.get(options1).getId() + "");
                    bean.setCityName(opt2.get(options1).get(options2).getName() + "");
                    bean.setCityNo(opt2.get(options1).get(options2).getId() + "");
                } else if (id == R.id.warehouse_land) {
                    binding.supplierBasics.basic.warehouseLand.setContent(addressEntityList.get(options1).getName() + " / " + opt2.get(options1).get(options2).getName());
                    bean.setStorageProvinceName(addressEntityList.get(options1).getName() + "");
                    bean.setStorageProvinceNo(addressEntityList.get(options1).getId() + "");
                    bean.setStorageCityName(opt2.get(options1).get(options2).getName() + "");
                    bean.setStorageCityNo(opt2.get(options1).get(options2).getId() + "");
                }
            }
        }).setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText(titles)
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .build();
        cityOption.setPicker(addressEntityList, opt2);
        cityOption.setSelectOptions(cityPosition1, cityPosition2);
        cityOption.show();
    }

    /**
     * 一级选择弹窗
     *
     * @param titles
     * @param inputTextView
     * @param data
     */
    private void showListPop(String titles, View inputTextView, List<JiCaiPublishListBean> data) {
        if (data != null && data.size() > 0) {
            OptionsPickerView<JiCaiPublishListBean> mCustomerOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    int id = inputTextView.getId();
                    if (id == R.id.publish_units) {//发起单位
                        binding.supplierBasics.basic.publishUnits.setContent(data.get(options1).getName() + "");
                        bean.setPickCompanyId(data.get(options1).getId() + "");
                        bean.setPickCompanyName(data.get(options1).getName() + "");
                    } else if (id == R.id.start_department) {//发起部门
                        binding.supplierBasics.basic.startDepartment.setContent(data.get(options1).getName() + "");
                        bean.setCreateDepartmentNo(data.get(options1).getId() + "");
                        bean.setCreateDepartment(data.get(options1).getName() + "");
                    } else if (id == R.id.payment_type) {//付款方式
                        binding.supplierPrivilege.surplus.paymentType.setContent(data.get(options1).getName() + "");
                        bean.setPayType(data.get(options1).getId());
                        switch (data.get(options1).getId()) {
                            case "1"://预付款
                                binding.supplierPrivilege.surplus.llPlanPayment.setVisibility(View.VISIBLE);
                                binding.supplierPrivilege.surplus.elsePaymentType.setVisibility(View.GONE);
                                break;
                            case "2"://货到付款
                                binding.supplierPrivilege.surplus.llPlanPayment.setVisibility(View.GONE);
                                binding.supplierPrivilege.surplus.elsePaymentType.setVisibility(View.GONE);
                                break;
                            case "3"://其他
                                binding.supplierPrivilege.surplus.llPlanPayment.setVisibility(View.GONE);
                                binding.supplierPrivilege.surplus.elsePaymentType.setVisibility(View.VISIBLE);
                                break;
                        }
                    } else if (id == R.id.invoice_type) {//发票类型
                        binding.supplierPrivilege.surplus.invoiceType.setContent(data.get(options1).getName() + "");
                        bean.setBillType(data.get(options1).getId());
                        if (data.get(options1).getId().equals("2")) {
                            binding.supplierPrivilege.surplus.taxRate.setVisibility(View.VISIBLE);
                        } else {
                            binding.supplierPrivilege.surplus.taxRate.setVisibility(View.GONE);
                        }
                    } else if (id == R.id.tax_rate) {//税率
                        binding.supplierPrivilege.surplus.taxRate.setContent(data.get(options1).getName() + "");
                        bean.setTaxRate(binding.supplierPrivilege.surplus.taxRate.getContent() + "");
                    } else if (id == R.id.communication_receive_name) {//交流信息接收人
                        binding.supplierBasics.basic.communicationReceiveName.setContent(data.get(options1).getName() + "");
                        bean.setCommunicationUserName(binding.supplierBasics.basic.communicationReceiveName.getContent() + "");
                        bean.setCommunicationUserMemberNo(data.get(options1).getId());
                    } else if (id == R.id.letter_receive_name) {//函询接收人
                        binding.supplierBasics.basic.letterReceiveName.setContent(data.get(options1).getName() + "");
                        bean.setInquiryUserName(binding.supplierBasics.basic.communicationReceiveName.getContent() + "");
                        bean.setInquiryUserMemberNo(data.get(options1).getNo() + "");
                    } else if (id == R.id.supervise_receive_name) {//监督接收人
                        binding.supplierBasics.basic.superviseReceiveName.setContent(data.get(options1).getName() + "");
                        SuperviseListBean lisbean = new SuperviseListBean();
                        lisbean.setSuperviseUserName(data.get(options1).getName() + "");
                        lisbean.setSuperviseUserMemberNo(data.get(options1).getNo() + "");
                        lisbean.setAccusationItem("0");
                        List<SuperviseListBean> superviseList = new ArrayList<>();
                        superviseList.add(lisbean);
                        bean.setSuperviseList(superviseList);
                    } else if (id == R.id.unit_measure) {//单位
                        binding.supplierBasics.jicai.unitMeasure.setContent(data.get(options1).getName() + "");
                        bean.setUnitName(binding.supplierBasics.jicai.unitMeasure.getContent() + "");
                        bean.setUnit(data.get(options1).getNo() + "");
                        binding.supplierBasics.jicai.rangeBrands.setContent("");//品牌
                        bean.setBrandsName("");
                        bean.setBrandsNo("");
                        binding.supplierBasics.jicai.productModel.setContent("");//规格型号
                        //清空规格型号字段
                        bean.setDetails(new ArrayList<>());
                    } else if (id == R.id.range_brands) {//品牌
                        binding.supplierBasics.jicai.rangeBrands.setContent(data.get(options1).getName() + "");
                        bean.setBrandsName(binding.supplierBasics.jicai.rangeBrands.getContent() + "");
                        bean.setBrandsNo(data.get(options1).getId() + "");
                        binding.supplierBasics.jicai.productModel.setContent("");//规格型号
                        //清空规格型号字段
                        bean.setDetails(new ArrayList<>());
                    }
                }
            }).setCancelColor(Color.parseColor("#666666"))
                    .setSubCalSize(15)
                    .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                    .setSubmitColor(Color.parseColor("#5792FD")).build();
            mCustomerOptions.setTitleText(titles);
            mCustomerOptions.setPicker(data);
            mCustomerOptions.setSelectOptions(0);
            mCustomerOptions.show();
        }
    }

    /**
     * 按类型设置监督人
     *
     * @param titles
     * @param bean
     * @param data
     */
    private void showSuperviseListPop(String titles, SuperviseListBean bean, List<JiCaiPublishListBean> data) {
        if (data != null && data.size() > 0) {
            OptionsPickerView<JiCaiPublishListBean> mCustomerOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    bean.setSuperviseUserName(data.get(options1).getName());
                    bean.setSuperviseUserMemberNo(data.get(options1).getNo());
                    superviseadapter.notifyDataSetChanged();
                }
            }).setCancelColor(Color.parseColor("#666666"))
                    .setSubCalSize(15)
                    .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                    .setSubmitColor(Color.parseColor("#5792FD")).build();
            mCustomerOptions.setTitleText(titles);
            mCustomerOptions.setPicker(data);
            mCustomerOptions.setSelectOptions(0);
            mCustomerOptions.show();
        }
    }

    /**
     * 地址列表数据信息
     *
     * @param data
     */
    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data, View view) {
        addressEntityList = data;
        for (int i = 0; i < addressEntityList.size(); i++) {
            opt2.add(addressEntityList.get(i).getChildren());
        }
        if (addressEntityList != null && addressEntityList.size() > 0) {
            showCityPop("选择城市", view);
        }
    }

    /**
     * 集采时间选择
     */
    private void showTimePop() {
        Calendar dayCalendar = Calendar.getInstance();
        dayCalendar.add(Calendar.DAY_OF_MONTH, 1);
        TimePickerView timePicker = new TimePickerBuilder(this, (date, v) -> {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String format = sdf.format(date);
            binding.supplierBasics.basic.buyTime.setContent(format);
            bean.setEndTime(String.valueOf(DateUtils.dateTo13Timestamp(format)));
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(dayCalendar, null)
                .build();
        timePicker.show();
    }

    /**
     * 发起单位
     *
     * @param data
     */
    public void setCompanyList(List<JiCaiPublishListBean> data, View view, boolean isShow) {
        this.companyList = data;
        if (isShow) {
            showListPop("发起单位", view, companyList);
        } else {
            for (JiCaiPublishListBean jiCaiPublishListBean : companyList) {
                if (jiCaiPublishListBean.getName().equals(company_name)) {
                    bean.setPickCompanyId(jiCaiPublishListBean.getId());
                }
            }
        }
    }

    /**
     * 发起部门
     *
     * @param data
     */
    public void setDepartmentList(List<JiCaiPublishListBean> data, View view) {
        this.departmentList = data;
        showListPop("发起部门", view, departmentList);
    }

    /**
     * 用户列表信息
     *
     * @param data
     * @param isboole
     */
    public void setUserList(List<JiCaiPublishListBean> data, View view, boolean isboole) {
        this.UserList = data;
        if (isboole) {
            showListPop("选择接收人", view, UserList);
        } else {
            for (JiCaiPublishListBean jiCaiPublishListBean : data) {
                if (jiCaiPublishListBean.getName().equals(userName)) {
                    //交流信息接收人
                    bean.setCommunicationUserMemberNo(jiCaiPublishListBean.getId());
                    //函询接收人
                    bean.setInquiryUserMemberNo( jiCaiPublishListBean.getNo()+ "");
                    //监督接收人
                    SuperviseListBean lisbean = new SuperviseListBean();
                    lisbean.setSuperviseUserName(userName + "");
                    lisbean.setSuperviseUserMemberNo(jiCaiPublishListBean.getNo() + "");
                    lisbean.setAccusationItem("0");
                    List<SuperviseListBean> superviseList = new ArrayList<>();
                    superviseList.add(lisbean);
                    bean.setSuperviseList(superviseList);
                }
            }
        }
    }

    /**
     * 付款方式
     *
     * @param data
     */
    public void setPaymentList(List<JiCaiPublishListBean> data, View view) {
        this.paymentList = data;
        showListPop("选择付款方式", view, paymentList);
    }

    /**
     * 发票类型
     *
     * @param data
     */
    public void setInvoiceList(List<JiCaiPublishListBean> data, View view) {
        this.invoiceList = data;
        showListPop("选择发票类型", view, invoiceList);
    }

    /**
     * 税率
     *
     * @param data
     */
    public void setTaxRateList(List<JiCaiPublishListBean> data, View view) {
        this.taxRateList = data;
        showListPop("选择税率", view, taxRateList);
    }

    /**
     * 单位信息
     *
     * @param data
     */
    public void setUnitList(List<JiCaiPublishListBean> data, View view) {
        this.unitList = data;
        showListPop("选择计量单位", view, unitList);
    }

    /**
     * 展示商品类型
     */
    private void showGoodsTypePop() {
        if (!goodsTypePopWindow.isShowing()) {
            goodsTypePopWindow.showDownPopwindow(binding.grayLayout, true);
        }
    }

    /**
     * 商品返回数据信息
     *
     * @param data
     */
    public void showGoodsTypePop(List<MenuEntity<MenuEntity<MenuEntity>>> data) {
        this.goodsTypeEntityList = data;
        if (!goodsTypePopWindow.isShowing()) {
            goodsTypePopWindow.showDownPopwindow(binding.grayLayout, true);
        }
        goodsTypePopWindow.setData(goodsTypeEntityList);
    }

    /**
     * 品牌范围
     *
     * @param data
     * @param view
     */
    public void showBrandPop(List<BrandEntity> data, View view) {
        this.brandList = new ArrayList<>();
        if (data != null && data.size() > 0) {
            for (int i = 0; i < data.size(); i++) {
                List<BrandEntity.BrandChild> childList = data.get(i).getChildList();
                if (childList != null && childList.size() > 0) {
                    for (int j = 0; j < childList.size(); j++) {
                        String name = childList.get(j).getName();
                        String id = childList.get(j).getId();
                        brandList.add(new JiCaiPublishListBean(name, "", id));
                    }
                }
            }
        }
        if (brandList.size() > 0) {
            showListPop("选择品牌范围", view, brandList);
        } else {
            MToast.showToast(this, "当前商品没有品牌");
        }
    }

    //上传图片返回路径信息
    public void uploadAvatarResult(String toString, SupplierPublishBean oneBean) {
        if (files == null) {
            files = new ArrayList<>();
        }
        files.add(toString);
    }

    //发布成功
    public void SucceedView() {
        setResult(Activity.RESULT_OK, new Intent());
        finish();
    }

    @Override
    public void onBackPressed() {
        initDialog();
    }

    public void initDialog() {
        new CommonDialog(getActivity()).builder().setPositiveButton("确定").setNegativeButton("取消")
                .setTitle("温馨提示")
                .setMsg("所填写的内容不会保存,确认离开？")
                .setDialogCallBack(new CommonDialog.DialogCallBack() {
                    @Override
                    public void onRightClick() {
                        setResult(Activity.RESULT_OK, new Intent());
                        JiCaiSupplierPublishAct.this.finish();
                    }

                    @Override
                    public void onLeftClick() {
                        return;
                    }
                }).show();
    };
}
